/**
 * @file spell.h
 * @brief Macros of the spell functions.
 * @date Dec-2011
 * @author Leonardo Lino 2101101
 * @author Joaquim Ferreira 2101104
 * @version 1.0
 */
 
#ifndef SPELL_H
#define SPELL_H

/** @brief This global integer variable (G_continue) will be used to treat the signal breakpoint to free all the resources.*/
extern int G_continue;
/** @brief This global integer variable (G_proc_lines) will contain the number of processed lines.*/
extern int G_proc_lines;
/** @brief This global integer variable (G_proc_files) will contain the number of processed files.*/
extern int G_proc_files;


/**
 * @brief Main processor for spell funcionality
 * @fn void mainSpell(const char *dictionary, const char *filename)
 * @param dictionary A pointer to the dictionary string.
 * @param filename A pointer to the filename string.
 */
void mainSpell(const char *dictionary, const char *filename);

/**
 * @brief Loads dictionary file into memory. Each element has a generic list that holds it's sinonims
 * @fn HASHTABLE_T  *dictLoader(const char *dictionary)
 * @param dictionary A pointer to the dictionary string.
 * @return Return a hashtable.
 */
HASHTABLE_T  *dictLoader(const char *dictionary);

/**
 * @brief Loads textfile into memory. Deprecated function. Replaced by getLinesOrWords(). Maintained for debugging purposes
 * @fn LISTA_GENERICA_T *fileLoader(const char *filename)
 * @param filename A pointer to the filename string.
 * @return Return a generic list.
 */
LISTA_GENERICA_T *fileLoader(const char *filename);


/**
 * @brief Check each word in textfile against the complete dictionary. 
 * @fn int checkDict(HASHTABLE_T* dictHolder, LISTA_GENERICA_T* resultsList, char *word)
 * @param dictHolder Pointer to the dictionary hashtable
 * @param resultsList Will be populated with any results that match criteria
 * @param word Word that will be comparared against dictionary
 * @return Return 0 or 1. If word is found in dictionary, return 1 else return 0
 */
int checkDict(HASHTABLE_T* dictHolder, LISTA_GENERICA_T* resultsList, char *word, HASHTABLE_T* resultsHash);

/**
 * @brief Used to compare to strings before insertion in a generic list
 * @fn int compareSinonims(char *prev, char *new)
 * @param prev The current string to compare against
 * @param new New string to compare before insertion
 * @return Return -1, 0 or 1 respectivly if "new" inferior, equal or greater then "prev"
 */
int compareSinonims(char *prev, char *new);

/**
 * @brief Function deprecated by freeDictHolder. Only maintainted for backword compatibility
 * @fn void free_tabela(LISTA_GENERICA_T* lista)
 * @param lista Generic list contained in each element of the hashtable
 */
void free_tabela(LISTA_GENERICA_T* lista);

/**
 * @brief Used to free hashtable and each generic list per element
 * @fn void freeDictHolder(HASHTABLE_T* tabela)
 * @param tabela Hashtable containing dictionary
 */
void freeDictHolder(HASHTABLE_T* tabela);

/**
 * @brief Used to alphabetically sort a string
 * @fn void reOrderSpell(char *str)
 * @param str Pointer to string that will be resorted
 */
void reOrderSpell(char *str);

/**
 * @brief Used to output to screen the final results
 * @fn void outputResults(HASHTABLE_T* totalResults)
 * @param totalResults Pointer to hashtable containg final results. This hashtable has a generic list for each element
 */
void outputResults(HASHTABLE_T* totalResults);

/**
 * @brief Used for debugging purposes. It outputs the elements contained in a generic list.
 * @fn void outputList (LISTA_GENERICA_T* lista)
 * @param lista Pointer to generic list to be shown
 */
void outputList (LISTA_GENERICA_T* lista);

#endif /* SPELL_H */
